Skip to content

Conditionally save FPU context in IRQ, and preserve vApplicationFPUSa…#1429

Open
Loustiic wants to merge 1 commit into
FreeRTOS:mainfrom
Loustiic:conditionally_save_FPU_context_in_IRQ
Open

Conditionally save FPU context in IRQ, and preserve vApplicationFPUSa…#1429
Loustiic wants to merge 1 commit into
FreeRTOS:mainfrom
Loustiic:conditionally_save_FPU_context_in_IRQ

Conversation

@Loustiic

Copy link
Copy Markdown

Description

On the ARM Cortex A9 port of the FreeRTOS kernel, the FPU is never saved when the application provides an implementation of vApplicationIRQHandler, even though configUSE_TASK_FPU_SUPPORT can be set to 1 or 2.

This is the case with Xilinx's FreeRTOS port for Zynq 7000 (tested on 7020 here).

It is important to save these registers, even if the FPU should never be used in the IRQ handler: memcpy, memset or memcmp might use it -- https://freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors#important-note-for-gcc-and-possibly-other-compiler-users.

In other words, using stream_buffers, queues or other memory APIs from FreeRTOS leads to FPU corruption when using GCC in an interrupt context.

For this reason, it makes sense to check ulPortTaskHasFPUContext, and save the FPU registers if necessary.

This issue was discussed (on the forum)[https://forums.freertos.org/t/floating-context-not-saved-properly-on-zynq7020/13250] for the Zynq 7020.

The patch is structured as followed:

  1. Check ulPortTaskHasFPUContext and save the FPU context if necessary in FreeRTOS_IRQ_Handler.
  2. Call vApplicationIRQHandler.
  3. Optional: If vApplicationFPUSafeIRQHandler is provided only save/restore the FPU context in weak vApplicationIRQHandler when ulPortTaskHasFPUContext is false -- it preserves existing behavior, and avoids an unecessary double save.
  4. Back in FreeRTOS_IRQ_Handler, restore the FPU context if ulPortTaskHasFPUContext is true.

Checklist:

  • I have tested my changes. The stack consumption and timing will get worse

Related Issue

Two PR for other architecture targeted a similar issue:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant